package com.yunzhong.appointment.illnesstpye.controller;
import javax.servlet.http.HttpServletRequest;
import com.github.pagehelper.PageInfo;
import com.yunzhong.appointment.entity.Illnessposition;
import com.yunzhong.appointment.illnesstpye.entity.ResultJson;
import com.yunzhong.appointment.illnesstpye.service.IllnessTypeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;
import com.yunzhong.appointment.util.PageData;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;
import java.util.UUID;

@Controller
public class IllnessTypeController {
    @Autowired

    private IllnessTypeService illnessTypeService;

    @RequestMapping("/illnessType/query")
    public String query(ModelMap modelMap, HttpServletRequest request) {
        PageData pd = new PageData(request);
        List<Illnessposition> list = illnessTypeService.query(pd);
        modelMap.addAttribute("page", new PageInfo<Illnessposition>(list));
        modelMap.addAttribute("pd", pd);
        return "ill/illnesstype/illnesstype";
    }

    @RequestMapping("/illnessType/addpage")
    public String addpage() {
        return "ill/illnesstype/illtyp_add";
    }

    @RequestMapping("/illnessType/addsave")
    @ResponseBody
    public ResultJson addsave(Illnessposition illnessposition) {
        illnessposition.setIlltpId(UUID.randomUUID().toString());
        int num = illnessTypeService.save(illnessposition);
        return ResultJson.out(num);
    }

    @RequestMapping("/illnessType/editpage")
    public String editpage(String id, ModelMap modelMap) {
        Illnessposition list = illnessTypeService.queryById(id);
        modelMap.addAttribute("list", list);
        return "ill/illnesstype/illtyp_edit";
    }

    @RequestMapping("/illnessType/editsave")
    @ResponseBody
    public ResultJson editsave(Illnessposition illnessposition) {
        System.out.println(illnessposition.getIlltpName()+"2222222222222");
        int num = illnessTypeService.edit(illnessposition);
        System.out.println("4444444444444444444"+num);
        return ResultJson.out(num);
    }

    @RequestMapping("/illnessType/delete")
    @ResponseBody
    public ResultJson delete(String[] ids) {
        String names = illnessTypeService.delete(ids);
        String value = "";
        ResultJson r=new ResultJson();
        if (value.equals(names)) {
            r.setSuccess(true);
        }else{
            r.setSuccess(false);
            r.setMsg(names);
        }
        return r;


    }
}
